package com.aro.utils;

import java.util.Map;

public class ParameterTool {
	
	/**
	 * this method is in charge of checking for empty Strings
	 * @param args
	 * @throws IllegalArgumentException when at least one argument is null or empty
	 */
	public static void checkMandatoryFields(Map<String,String> fields){
		StringBuilder fail = null;
		for(String oneField : fields.keySet()){
			String oneValue = fields.get(oneField);
			if(oneValue == null || oneValue.equals("")){
				if(fail == null){
					fail = new StringBuilder();
				}
				fail.append(String.format("- %s \n", oneField));
			}
		}
		if(fail != null)
			throw new IllegalArgumentException(String.format("Todos los campos son mandatorios:\n %s", fail.toString()));
	}
	/**
	 * It is responsible for checking if a value is an integer
	 * @param field
	 * @param value
	 */
	public static void checkInteger(String field, String value){
		try{
			int i = Integer.valueOf(value);
		}catch(IllegalArgumentException e){
			throw new IllegalArgumentException(String.format("El Campo %s debe ser un entero", field));
		}
	}
}
